﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM; 

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class ES_MoveRequestJobsite : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        private IJobSiteBLL jsBLL = new JobSiteBLL();
        private string id;
        private object _dataItem = null;
        String JobSiteType = "1";

        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!IsUserControlPostBack)
            {


              

                ListJobSiteComboBox(JobSiteType, "");

                lblEmpSeq.Text = ssMng.EmpSeq;
                lbl_req_seq.Text = Session["req_seq"].ToString();  

             
                this.ViewState.Add("IsUserControlPostBack", true);
            }

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {

                    ListJobSiteComboBox(JobSiteType, "");
                    txtNo.Text = DataBinder.Eval(DataItem, "seq").ToString();
                    txtReason.Text = DataBinder.Eval(DataItem, "reason").ToString();
                    cbJobsite.SelectedValue = DataBinder.Eval(DataItem, "job_site_seq").ToString();
                    lbl_id.Text = DataBinder.Eval(DataItem, "id").ToString();
                  
             

                    this.btnAddnew.Visible = false;
                    this.btnUpdate.Visible = true;
                }
                else
                {
                    this.btnUpdate.Visible = false;
                    this.btnAddnew.Visible = true;
                }


            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

               
        }



        private void ListJobSiteComboBox(string JobSiteType)
        {
            ListJobSiteComboBox(JobSiteType, "");
        }
        private void ListJobSiteComboBox(string JobSiteType, string JobSiteLevel)
        {
            IList<JobSiteInfo> InfoList = jsBLL.ListJobSiteByTypes(JobSiteType, JobSiteLevel);

            cbJobsite.DataSource = InfoList;
            cbJobsite.DataBind();
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        
        //**************  Insert  ************************************
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
                       
            
            MoveRequestJobsiteBLL obj = new MoveRequestJobsiteBLL();

            
        
            string seq;
            seq = txtNo.Text.ToString();  
           
            obj.Insert_hrm_es_move_request_dtls(int.Parse(lbl_req_seq.Text)  ,int.Parse(seq), int.Parse(cbJobsite.SelectedValue),txtReason.Text, 1);    
            
                
           

        }


        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            MoveRequestJobsiteBLL obj = new MoveRequestJobsiteBLL();
          

            string reason, seq;
            
            reason = txtReason.Text.ToString();
            seq = txtNo.Text.ToString();

            obj.Update(int.Parse(lbl_id.Text), int.Parse(seq), int.Parse(cbJobsite.SelectedValue), reason, 1);    
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}